package com.bestom.bluetoothlock.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class DataUtils {
    public static String transformTime(long j) {
        return new SimpleDateFormat("yyyy-MM-dd").format(Long.valueOf(j));
    }

    public static long transformMillisecond(String str) {
        try {
            return new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA).parse(str).getTime();
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    public static String transformTime2(long j) {
        return new SimpleDateFormat("MM.dd").format(Long.valueOf(j));
    }

    public static String transformTime3(long j) {
        return new SimpleDateFormat("MM-dd").format(Long.valueOf(j));
    }

    public static String transformTime4(long j) {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Long.valueOf(j));
    }

    public static String transformTime5(long j) {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(Long.valueOf(j));
    }

    public static String transformTime6(long j) {
        return new SimpleDateFormat("HH:mm").format(Long.valueOf(j));
    }

    public static String transformTime7(long j) {
        return new SimpleDateFormat("yy.MM.dd").format(Long.valueOf(j));
    }

    public static int getCurrentYear() {
        return Calendar.getInstance().get(1);
    }

    public static int getCurrentMonth() {
        return Calendar.getInstance().get(2) + 1;
    }

    public static int getCurrentDay() {
        return Calendar.getInstance().get(5);
    }

    public static String getWeek(String str) {
        String str2 = "";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Calendar instance = Calendar.getInstance();
        try {
            instance.setTime(simpleDateFormat.parse(str));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        if (instance.get(7) == 1) {
            str2 = str2 + "日";
        }
        if (instance.get(7) == 2) {
            str2 = str2 + "一";
        }
        if (instance.get(7) == 3) {
            str2 = str2 + "二";
        }
        if (instance.get(7) == 4) {
            str2 = str2 + "三";
        }
        if (instance.get(7) == 5) {
            str2 = str2 + "四";
        }
        if (instance.get(7) == 6) {
            str2 = str2 + "五";
        }
        if (instance.get(7) != 7) {
            return str2;
        }
        return str2 + "六";
    }

    public static int getAge(long j) {
        Calendar instance = Calendar.getInstance();
        if (j >= instance.getTimeInMillis()) {
            return 1;
        }
        int i = instance.get(1);
        int i2 = instance.get(2);
        int i3 = instance.get(5);
        instance.setTime(new Date(j));
        int i4 = instance.get(1);
        int i5 = instance.get(2);
        int i6 = instance.get(5);
        int i7 = i - i4;
        if (i2 <= i5) {
            if (i2 != i5) {
                i7--;
            } else if (i3 < i6) {
                i7--;
            }
        }
        if (i7 == 0) {
            return 1;
        }
        return i7;
    }
}
